package com.huawei.appgallery.appcomment.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ToggleButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.appcomment.api.IUserCommentListFragmentProtocol;
import com.huawei.appgallery.appcomment.impl.bean.CommentTabInfoBean;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.ArrayList;
import java.util.List;
import o.bcg.d;
import o.bda;
import o.ciz;
import o.cvt;
import o.Logger;
import o.CollectCheck;
import o.fjm;
import o.FragmentTransaction;

@FragmentDefine(alias = "UserCommentListFragment", protocol = IUserCommentListFragmentProtocol.class)
public class UserCommentListFragment extends TaskFragment<AppListFragmentProtocol> implements OnClickListener, ciz {
    private boolean ʼ = true;
    protected String ˊ = "";
    private int ˋ;
    private ToggleButton ˎ;
    private ToggleButton ˏ;
    private fjm ॱ = fjm.ॱ(this);
    private ToggleButton ॱॱ;
    private boolean ᐝ = true;

    public void ˏ(Bundle bundle) {
        this.ˊ = ˊॱ().getString("app_comments_list_request_accountid");
        IUserCommentListFragmentProtocol iUserCommentListFragmentProtocol = (IUserCommentListFragmentProtocol) this.ॱ.ॱ();
        if (iUserCommentListFragmentProtocol != null && TextUtils.isEmpty(this.ˊ)) {
            this.ˊ = iUserCommentListFragmentProtocol.getUserId();
        }
        this.ʼ = true;
        super.ˏ(bundle);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(d.ʻ, null);
        this.ˏ = (ToggleButton) inflate.findViewById(e.ᐝॱ);
        this.ˎ = (ToggleButton) inflate.findViewById(e.ˋˊ);
        this.ॱॱ = (ToggleButton) inflate.findViewById(e.ͺ);
        if (!this.ʼ) {
            ˋॱ(this.ᐝ);
        }
        return inflate;
    }

    public void ˊ(@NonNull View view, @Nullable Bundle bundle) {
        if (bundle == null) {
            this.ˋ = 0;
        } else {
            this.ˋ = bundle.getInt("currently_showing_fragment");
        }
        if (!this.ʼ) {
            ˋ(e.ᵢ, this.ˋ, this.ᐝ);
        }
        super.ˊ(view, bundle);
    }

    public void onClick(View view) {
        if (view.getId() == e.ᐝॱ) {
            ˋ(0);
            ॱ(this.ˏ);
        } else if (view.getId() == e.ˋˊ) {
            ˋ(1);
            ॱ(this.ˎ);
        } else if (view.getId() == e.ͺ) {
            ˋ(2);
            ॱ(this.ॱॱ);
        }
    }

    private void ˋ(int i, int i2, boolean z) {
        FragmentTransaction ˊ = ʽॱ().ˊ();
        List ˏ = ʽॱ().ˏ();
        ArrayList arrayList = new ArrayList();
        if (CollectCheck.isEmpty(ˏ)) {
            Fragment ॱ = MyCommentListFragment.ॱ(this.ˊ);
            Fragment ˎ = UserReplyListFragment.ˎ(this.ˊ);
            arrayList.add(ॱ);
            arrayList.add(ˎ);
            ˊ.ˋ(i, ॱ);
            ˊ.ˋ(i, ˎ);
            if (z) {
                ॱ = UserCollectionListFragment.ˊʻ();
                arrayList.add(ॱ);
                ˊ.ˋ(i, ॱ);
            }
        } else {
            arrayList.addAll(ˏ);
        }
        for (int i3 = 0; i3 < arrayList.size(); i3++) {
            if (i2 != i3) {
                ˊ.ॱ((Fragment) arrayList.get(i3));
            }
        }
        ˊ.ˋ();
    }

    private void ˋॱ(boolean z) {
        this.ˏ.setOnClickListener(this);
        this.ˏ.setVisibility(0);
        this.ˎ.setOnClickListener(this);
        this.ˎ.setVisibility(0);
        if (z) {
            this.ॱॱ.setVisibility(0);
            this.ॱॱ.setOnClickListener(this);
        }
        ॱ(this.ˏ);
    }

    private void ˋ(int i) {
        this.ˋ = i;
        List<Fragment> ˏ = ʽॱ().ˏ();
        if (i <= ˏ.size() && i != ˏ.size()) {
            for (Fragment fragment : ˏ) {
                if (fragment != null) {
                    ʽॱ().ˊ().ॱ(fragment).ˋ();
                }
            }
            if (ˏ.get(i) != null) {
                ʽॱ().ˊ().ˏ((Fragment) ˏ.get(i)).ˋ();
            }
        }
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("forum|user_detail_review");
        if (!TextUtils.isEmpty(this.ˊ)) {
            stringBuilder.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ);
        }
        list.add(new bda(stringBuilder.toString(), 1));
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        if (bVar.ˋ instanceof BaseDetailResponse) {
            List ᐝॱ = ((BaseDetailResponse) bVar.ˋ).ᐝॱ();
            if (!CollectCheck.isEmpty(ᐝॱ)) {
                ᐝॱ = ((LayoutData) ᐝॱ.get(0)).ˋ();
                if (!CollectCheck.isEmpty(ᐝॱ)) {
                    Object obj = ᐝॱ.get(0);
                    if (obj instanceof CommentTabInfoBean) {
                        this.ᐝ = "0".equals(((CommentTabInfoBean) obj).ॱ());
                    }
                }
            }
            ˋॱ(this.ᐝ);
            ˋ(e.ᵢ, this.ˋ, this.ᐝ);
            this.ʼ = false;
        }
        return false;
    }

    private void ॱ(ToggleButton toggleButton) {
        this.ˏ.setChecked(false);
        this.ˎ.setChecked(false);
        this.ॱॱ.setChecked(false);
        toggleButton.setChecked(true);
    }

    public boolean ad_() {
        List ˏ = ʽॱ().ˏ();
        if (ˏ.size() > this.ˋ) {
            Fragment fragment = (Fragment) ˏ.get(this.ˋ);
            if (fragment instanceof ciz) {
                return ((ciz) fragment).ad_();
            }
            Logger.e("TaskFragment", "unknown type, fragment:" + fragment);
        }
        return false;
    }

    public void ˋ(@NonNull Bundle bundle) {
        super.ˋ(bundle);
        bundle.putInt("currently_showing_fragment", this.ˋ);
    }
}
